/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package WS;
import BD.Modulos.BdProveedor;
import Interfaces.BdException;
import Interfaces.SupplierInterface;
import Objects.GroupSupplier;
import Objects.Supplier;
import WS.Respuestas.RespBdProveedor;
import java.sql.SQLException;
import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.WebServiceContext;
/**
 *
 * @author ARMGARCES
 */
@WebService(serviceName = "Proveedor")
public class Proveedor {
    public final static int CHECK_SUPPLIER = 0;
    public final static int CHECK_GROUP    = 1;
    @Resource
    WebServiceContext wsContext;      
    /***************************************************************************/
    /******************************** SUPPLIER *********************************/
    /***************************************************************************/
    /**
     * 
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "loadSupplier")
    public synchronized Supplier[] loadSupplier() throws BdException {
        try{
            return (Supplier[]) BdProveedor.getInstance().load(new Supplier());      
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }
        return null;
    }    
    /**
     * 
     * @param find
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "findSupplier")
    public synchronized Supplier[] findSupplier(@WebParam(name = "find")String find) throws BdException {        
        try{
            return (Supplier[]) BdProveedor.getInstance().find(new Supplier(),find);                  
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }
        return null;
    }    
    /**
     * 
     * @param user
     * @param supplier
     * @param operacion
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "saveSupplier")
    public synchronized boolean saveSupplier(@WebParam(name = "user")String user,
                                                      @WebParam(name = "supplier")Supplier supplier,
                                                      @WebParam(name = "operacion")int operacion) throws BdException {
        try{                
            return BdProveedor.getInstance().saveSupplier(user,operacion, supplier);
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }       
        return false;
    }
    /**
     * 
     * @param rif
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "checkSupplier")
    public synchronized RespBdProveedor checkSupplier(@WebParam(name = "rif")String rif) throws BdException {    
        RespBdProveedor resp = new RespBdProveedor(0);
        try{
            return BdProveedor.getInstance().check(CHECK_SUPPLIER,rif);                
        }catch(BdException bde){
            //resp.setError(bde.getMessage());
            throw bde;
        }catch(SQLException e){             
        }
        return resp;
    }
    /**
     * 
     * @param user
     * @param supplier
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "changeSupplier")
    public synchronized boolean changeSupplier(@WebParam(name = "user")String user,
                                                        @WebParam(name = "supplier")Supplier supplier) throws BdException {       
        try{
            return BdProveedor.getInstance().change(user,supplier);                
        }catch(BdException bde){
            throw bde;
        }catch(SQLException e){             
        }
        return false;
    }  
    /***************************************************************************/
    /***************************** GROUPSUPPLIER *******************************/
    /***************************************************************************/
    /**
     *
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "loadGroupSupplier")
    public GroupSupplier[] loadGroupSupplier() throws BdException {
        try{
            return (GroupSupplier[]) BdProveedor.getInstance().load(new GroupSupplier());      
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }
        return null;
    }    
    /**
     * 
     * @param find
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "findGroupSupplier")
    public GroupSupplier[] findGroupSupplier(@WebParam(name = "find")String find) throws BdException {        
        try{
            return (GroupSupplier[]) BdProveedor.getInstance().find(new GroupSupplier(),find);                  
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }
        return null;
    }    
    /**
     * 
     * @param user
     * @param groupSupplier
     * @param operacion
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "saveGroupSupplier")
    public boolean saveGroupSupplier(@WebParam(name = "user")String user,
                                              @WebParam(name = "groupSupplier")GroupSupplier groupSupplier, 
                                              @WebParam(name = "operacion")int operacion) throws BdException {        
        //boolean boo = Validar.validar_Save_GroupSupplier(groupsupplier);
        //if (boo){
            try{                
                return BdProveedor.getInstance().saveGroupSupplier(user,operacion, groupSupplier);
            }catch(BdException bde){
                throw bde;
            } catch (SQLException ex) {
        }       
        return false;
    }
    /**
     * 
     * @param groupName
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "checkGroupSupplier")
    public RespBdProveedor checkGroupSupplier(@WebParam(name = "groupName")String groupName) throws BdException {
        RespBdProveedor resp = new RespBdProveedor(0);
        try{
            return BdProveedor.getInstance().check(CHECK_SUPPLIER,groupName);                
        }catch(BdException bde){
            throw bde;
        }catch(SQLException e){             
        }
        return resp;
    }
    /**
     * 
     * @param user
     * @param groupSupplier
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "changeGroupSupplier")
    public boolean changeGroupSupplier(@WebParam(name = "user")String user, 
                                                @WebParam(name = "groupSupplier")GroupSupplier groupSupplier) throws BdException {
        try{
            return BdProveedor.getInstance().change(user,groupSupplier);                
        }catch(BdException bde){
            throw bde;
        }catch(SQLException e){             
        }
        return false;
    }  
}
